<?php

/**
 * CambioDirector form.
 *
 * @package    sistema_estadisticas
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class CambioDirectorForm extends BaseCambioDirectorForm
{

	public function configure()
	{
		$this->widgetSchema['tesis_id'] = new sfWidgetFormInputHidden();
		$this->widgetSchema['f_asignacion'] = new WidgetFormDatePick();
		$this->widgetSchema['director_anterior_id'] = new WidgetFormHiddenInfo(
			array(
				'display_value' => $this->getObject()->getDirectorAnterior(),
				'model' => 'Docente',
				'column' => array('last_name', 'first_name')
			)
		);

		$this->widgetSchema['director_asignado_id'] = new WidgetFormAutocomplete(
			array(
				'model' => 'Docente', 
				'action' => 'docente/buscar',
				'values' => array($this->getObject()->getDirectorAsignado())
			)
		);

		if ($this->isNew())
		{
			$this->widgetSchema->offsetGet('director_anterior_id')->setLabel('Director actual');

			//se crean con datos vacios, error al guardar
			$this->getObject()->__unset('DirectorAnterior'); 
			$this->getObject()->__unset('DirectorAsignado');
		}
	}
	
	protected function doSave($con = null)
	{
		if (null === $con)
			$con = $this->getConnection();

		$this->updateObject();
		$this->getObject()->save($con);

		//actualiza el director del proyecto de tesis
		if ($this->isNew())
			TesisTable::getInstance()->actualizaDirector($this->getObject()->getTesisId(), $this->getObject()->getDirectorAsignadoId());
	}

}
